package com.le.tester.book.concurrentchallenge.aviodDanger;


import java.awt.*;

/**
 * createTime：2025-04-22 9:46
 * description：在相互协作对象之间的锁顺序死锁（不要这么做）
 */
public class Taxi {
    private Point location, destination;
    private final Dispatcher dispatcher;

    public Taxi(Dispatcher dispatcher) {
        this.dispatcher = dispatcher;
    }


    public synchronized Point getPoint() {
        return location;
    }

    public synchronized void setLocation(Point location) {
        this.location = location;
        if (location.equals(destination)) {
            dispatcher.notifyAvailable(this);
        }
    }
}
